<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/1
 * Time: 16:50
 */

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Poundage extends Model {
	/**
	 * 系统设置
	 * @var string
	 */
	protected $table = 'set_poundage';
	protected $fillable = [
		'id',
		'redelivery',
		'redelivery_money',
		'platform_fee',
		'poundage',
		'withdrawal_day',
		'withdrawal_money',
		'DT_equity',
		'province',
		'city',
		'area',
		'equity',
		'return_rate',
        'DT_rate',
        'day_times',
        'day_probability',
        'distribution',
        'team_profit',
        'platform_profit',
        'switch',
        'ceo',
        'store',
        'bind_store',
		'platform',
        'investment',
        'store_platform',
        'deduction',
        'set_order_consumption',
        'set_order_team',
        'subsidy_money',
        'subsidy_reward',
	];
    public function find_poundage()
    {
        return $this->where(['id' => 1])->first();
	}

    /**
     * 计算 扣除平台费和复投费
     * @param int $recommend
     * @return array
     */
    public function calculate( $recommend = 0)
    {
        $Poundage = $this->where(['id' => 1])->first()->toArray();
        //平台费
        $platform_fee = RETAIN_TWO($recommend * ($Poundage['platform_fee'] * 0.01));
        //复投费
        $redelivery = RETAIN_TWO($recommend * ($Poundage['redelivery'] * 0.01));
        //最终得到的费用
        $recommendMoney = $recommend - ($platform_fee + $redelivery);
        return ['redelivery' => $redelivery ,'money' => $recommendMoney];
	}
}